package bean;

/**
 * Created by Administrator on 2018/6/25.
 */
import java.lang.Exception;
import java.lang.String;
import java.lang.System;
import java.sql.*;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
class dbbean{
    private String driverStr="com.mysql.jdbc.Driver";
    private String connStr="jdbc:mysql://localhost:3306/sctu_javaweb_2018?serverTimezone=UTC";
    private String name="root";
    private String password="123456";
    private Connection conn=null;
    private Statement stmt=null;
    public dbbean(){
        try{
            Class.forName(driverStr);
            conn=DriverManager.getConnection(connStr,name,password);
            stmt=conn.createStatement();

    }
        catch(Exception ex){
            System.out.println("no connect");
        }
    }
    public int executeUpdate(String s){
        int result=0;
        try{
            result=stmt.executeUpdate(s);
        }
        catch(Exception ex){
            System.out.println("update wrong!");
        }
        return result;
    }
    public ResultSet executeQuery(String s){
        ResultSet rs=null;
        try{
            rs=stmt.executeQuery(s);

        }
        catch(Exception ex){
            System.out.println("check wrong!");
        }
        return rs;
    }
    public void close(){
        try{stmt.close();conn.close();
        }
        catch(Exception ex){
            System.out.println("close!");
        }

    }
}
